//文件模块，安装：npm i fs
let fs = require('fs');
//百度OCR，安装：npm install baidu-aip-sdk
let AipOcrClient = require("baidu-aip-sdk").ocr;

// 设置APPID/AK/SK
let APP_ID = "14981161";
let API_KEY = "VuSwamuO4PHzb7dODshZOrSf";
let SECRET_KEY = "97yDfeCDI22sd0SWO3hqS7drnkx5GEGq";
// 新建一个对象，建议只保存一个对象调用服务接口
let client = new AipOcrClient(APP_ID, API_KEY, SECRET_KEY);

/**
 * 基于百度OCR的验证码识别工具类
 * @type {{load: (function(*=): Promise)}}
 */
const Tool = {load,};

/**
 * 解析图片验证码
 * @param imagePath 图片的路径
 */
function load(imagePath) {
  let image = fs.readFileSync(imagePath).toString("base64");
  return client.generalBasic(image);
}

module.exports = Tool;
